package com.dtmiao.app.controller;

import com.dtmiao.app.domain.Account;
import com.dtmiao.app.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/ssm")
public class SsmController {

    @Autowired
    private AccountService as;

    @RequestMapping("/findAll")
    public String findAll(Model model){
        System.out.println("表现层");
        List<Account> all = as.findAll();
        model.addAttribute("accounts",all);
        return "success";
    }

    @RequestMapping("/saveAccount")
    public void saveAccount(Account account, HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入到controller层");
        as.saveAccount(account);
        response.sendRedirect(request.getContextPath()+"/ssm/findAll");
    }
}
